﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
CREATE TABLE dbo.bht_AssemblyVersions
(
	FeatureAssembly		NVARCHAR(400) NOT NULL,
	DbVersion			NVARCHAR(100) NOT NULL
)  ON [PRIMARY]
GO


CREATE PROCEDURE dbo.bhp_AssemblyVersionsGet
AS
BEGIN
	
	IF OBJECT_ID('bht_Versions') IS NOT NULL
	BEGIN
		INSERT INTO dbo.bht_AssemblyVersions (FeatureAssembly, DbVersion)
			SELECT Feature, DbVersion FROM bht_Versions v WHERE Feature NOT IN (SELECT FeatureAssembly FROM dbo.bht_AssemblyVersions)
	END

	SELECT 
		FeatureAssembly,
		DbVersion
	FROM
		dbo.bht_AssemblyVersions
END
GO


CREATE PROCEDURE dbo.bhp_AssemblyVersionsSet
(
	@FeatureAssembly	NVARCHAR(400),
	@DbVersion			NVARCHAR(100)
)
AS
	IF EXISTS (SELECT 1 FROM dbo.bht_AssemblyVersions WHERE FeatureAssembly = @FeatureAssembly)
		UPDATE
			dbo.bht_AssemblyVersions 
		SET
			DbVersion			= @DbVersion
		WHERE 
			FeatureAssembly		= @FeatureAssembly
	ELSE
		INSERT INTO dbo.bht_AssemblyVersions (FeatureAssembly, DbVersion)
			VALUES (@FeatureAssembly, @DbVersion)
GO
